
import { createApp } from 'vue'
import App from './App.vue'
import router from '@/router'
// 导入全局样式
import './assets/css/global.css' 
// 导入本地配置项
import { loadConfig, ConfigPlugin } from './utils/config'
// 导入pinia
import { createPinia } from 'pinia'
// 导入pinia持久化插件
import { createPersistedState } from 'pinia-plugin-persistedstate'

// element-plus引入
import ElementPlus from 'element-plus' 
import 'element-plus/dist/index.css' 
import zhCn from 'element-plus/es/locale/lang/zh-cn' //设置为中文
import * as ElementPlusIconsVue from '@element-plus/icons-vue' //引入图标
// element-plus引入

const initApp = async () => {
  
  const app = createApp(App);
  // 先加载配置
  const config = await loadConfig();
  // 安装配置插件
  app.use(ConfigPlugin);
  // 将配置注入根组件（可选）
  app.provide('globalConfig', config);

  // 创建pinia实例
  const pinia = createPinia();
  // 创建pinia持久化实例
  const persist = createPersistedState();
  pinia.use(persist)
  app.use(pinia)
  
  
  // element-plus-icons-vue 图标组件全局导入
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }

  app.use(router)

  // element-plus引入 设置为中文
  app.use(ElementPlus, {
    locale: zhCn,
  })
    
  app.mount('#app');
};

initApp();
